home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / stack.cls < prev    next >
Text File  |  1997-06-14  |  2KB  |  75 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "CStack"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. Option Explicit
  11.  
  12. Public Enum EErrorStack
  13.     eeBaseStack = 13230     ' CStack
  14. End Enum
  15.  
  16. Private av() As Variant
  17. Private Const cChunk = 10
  18. Private iLast As Long, iCur As Long
  19.  
  20. Sub Push(vArg As Variant)
  21.     iCur = iCur + 1
  22.     On Error GoTo FailPush
  23.     If IsObject(vArg) Then
  24.         Set av(iCur) = vArg
  25.     Else
  26.         av(iCur) = vArg
  27.     End If
  28.     Exit Sub
  29. FailPush:
  30.     iLast = iLast + cChunk  ' Grow
  31.     ReDim Preserve av(1 To iLast) As Variant
  32.     Resume                  ' Try again
  33. End Sub
  34.  
  35. Function Pop() As Variant
  36.     If iCur Then
  37.         If IsObject(av(iCur)) Then
  38.             Set Pop = av(iCur)
  39.         Else
  40.             Pop = av(iCur)
  41.         End If
  42.         iCur = iCur - 1
  43.         If iCur < (iLast - cChunk) Then
  44.             iLast = iLast - cChunk      ' Shrink
  45.             ReDim Preserve av(1 To iLast) As Variant
  46.         End If
  47.     End If
  48. End Function
  49.  
  50. Property Get Count() As Long
  51.     Count = iCur
  52. End Property
  53. '
  54.  
  55. #If fComponent = 0 Then
  56. Private Sub ErrRaise(e As Long)
  57.     Dim sText As String, sSource As String
  58.     If e > 1000 Then
  59.         sSource = App.ExeName & ".Stack"
  60.         Select Case e
  61.         Case eeBaseStack
  62.             BugAssert True
  63.        ' Case ee...
  64.        '     Add additional errors
  65.         End Select
  66.         Err.Raise COMError(e), sSource, sText
  67.     Else
  68.         ' Raise standard Visual Basic error
  69.         sSource = App.ExeName & ".VBError"
  70.         Err.Raise e, sSource
  71.     End If
  72. End Sub
  73. #End If
  74.  
  75.